package cn.com.anysdk.oss.config;

import cn.com.anysdk.oss.api.IOssConfig;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

public class AliyunOssConfig implements IOssConfig {
    private String endpoint;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;
    private boolean isPrivate;
    private boolean isIntranet;
    private String customDomain;

    public OSS createOssClient() {
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }

    @Override
    public String getProvider() {
        return "aliyun";
    }

    @Override
    public boolean isPrivateMode() {
        return isPrivate;
    }

    @Override
    public boolean isIntranet() {
        return isIntranet;
    }

    @Override
    public String getCustomDomain() {
        return customDomain;
    }

    // Builder pattern for easy configuration
    public static class Builder {
        private final AliyunOssConfig config;

        public Builder() {
            config = new AliyunOssConfig();
        }

        public Builder endpoint(String endpoint) {
            config.endpoint = endpoint;
            return this;
        }

        public Builder accessKeyId(String accessKeyId) {
            config.accessKeyId = accessKeyId;
            return this;
        }

        public Builder accessKeySecret(String accessKeySecret) {
            config.accessKeySecret = accessKeySecret;
            return this;
        }

        public Builder bucketName(String bucketName) {
            config.bucketName = bucketName;
            return this;
        }

        public Builder isPrivate(boolean isPrivate) {
            config.isPrivate = isPrivate;
            return this;
        }

        public Builder isIntranet(boolean isIntranet) {
            config.isIntranet = isIntranet;
            return this;
        }

        public Builder customDomain(String customDomain) {
            config.customDomain = customDomain;
            return this;
        }

        public AliyunOssConfig build() {
            // Validate required fields
            if (config.endpoint == null || config.accessKeyId == null ||
                config.accessKeySecret == null || config.bucketName == null) {
                throw new IllegalStateException("Required fields cannot be null");
            }
            return config;
        }
    }

    // Getters
    public String getEndpoint() {
        return endpoint;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public String getBucketName() {
        return bucketName;
    }

    public boolean isPrivate() {
        return isPrivate;
    }

    public void setIntranet(boolean isIntranet) {
        this.isIntranet = isIntranet;
    }

    public void setCustomDomain(String customDomain) {
        this.customDomain = customDomain;
    }
}